二叉树的直径
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    int ans=1;
    int TreeHeigh(TreeNode* root)
    {
        if(root==nullptr)
            return 0;
        int lefth=TreeHeigh(root->left);
        int righth=TreeHeigh(root->right);
        ans=max(ans,lefth+righth+1);
        return max(lefth,righth)+1;
    }
    int diameterOfBinaryTree(TreeNode* root) {
        if(root==nullptr)
            return 0;
       TreeHeigh(root);
        
        return ans-1;
    }
};